﻿using JetBrains.Annotations;
using Missbot.AIModule.Base;
using Missbot.AIModule.OnlineStore;
using Missbot.Core.Base;
using Missbot.Model.MsgInfos;

namespace Missbot.AIModule.Gaming.ChessAgainst
{
    [UsedImplicitly]
    public class ChessAgainstMod : IAIModule
    {
        public override string Name => "对决";

        #region Svcs

        public ChessSvc ChessSvc { get; set; }
        public WaiterSvc WaiterSvc { get; set; }

        #endregion

        [ModuleEnter(Command = "对决 决斗",
                     Description = "指定一名成员进行对决",
                     DailyLimit = 1,
                     SyntaxHint = "[@用户名]",
                     ChannelType = ChannelType.Messaging)]
        public bool Fight(InboxSession session, InstanceUser aimUser)
        {
            if (aimUser.ID == session.User.ID)
            {
                session.SendBack("你无法跟自己对决！");
                return false;
            }

            if (aimUser.IsBot)
            {
                session.SendBack("鱼唇的人类，你无法挑战ai的威严！");
                return false;
            }

            if (ChessSvc.IsGroupInPlaying(session.Group.ID))
            {
                session.SendBack("本群正在进行一场对决，请稍后再试！");
                return false;
            }

            if (OSPersonBuffDA.CheckBuff(session.User.ID, "黄砂"))
            {
                session.SendBack("你当前无法进行挑战！(黄砂)");
                return false;
            }

            if (!WaiterSvc.WaitForConfirm(new InboxSession
            {
                Group = session.Group,
                User = aimUser,
                Channel = session.Channel
            }, $"{session.User.UserName} 正在向你发起一场对决，是否接受？", 10))
            {
                session.SendBack("对决取消！");
                return false;
            }

            if (ChessSvc.IsUserInPlaying(session.User.ID))
            {
                session.SendBack("你正在进行一场对决，请稍后再试！");
                return false;
            }

            if (ChessSvc.IsUserInPlaying(aimUser.ID))
            {
                session.SendBack("你的对手正在进行一场对决，请稍后再试！");
                return false;
            }

            ChessSvc.StartAGame(session.Group, session.User, aimUser, session.Channel);
            return true;
        }
    }
}